<template>
  <div class="uc-user">
    <ul class="user-btns ui-flex ui-flex--center" v-if="loginStatus == 0">
      <nuxt-link to="/base/login" class="ui-btn is-link" href>{{
        $t("header.user.btn_login")
      }}</nuxt-link>
      <!-- 免费注册 -->
      <a class="ui-btn is-link" href>{{ $t("header.user.btn_register") }}</a>
    </ul>
    <el-popover
      placement="top-start"
      width="308"
      trigger="click"
      v-else
      popper-class="header-user-poppver"
    >
      <div class="uc-user__user--logining ui-flex" slot="reference">
        <span class="user--lesson" @click="toProfile(1)">{{
          $t("header.user.lesson_text")
        }}</span>
        <img class="ui-avatar is-large" :src="avatar" alt />
      </div>
      <template>
        <div class="header-user__poppver-container">
          <!-- 用户信息 -->
          <div class="poppver-user ui-flex flex--column">
            <!-- 用户的头像 -->
            <div class="user-container ui-flex">
              <div class="user-avatar">
                <img :src="avatar" class="ui-avatar is-xss" :alt="nickName" />
              </div>
              <!-- 用户的详细信息 -->
              <div class="user-meta">
                <div class="user-info ui-flex flex--center">
                  <div class="ui-txt">{{ nickName }}</div>
                  <!-- 用户的徽章 -->
                  <div class="user-info__tags">
                    <!-- vip徽章 -->
                    <span>
                      <img :src="vipIconUrl" width="17" height="17" />
                    </span>
                    <span>
                      <img :src="diamondIconUrl" width="17" height="17" />
                    </span>
                  </div>
                </div>
                <div class="user-description ui-txt txt-caption">
                  正在使用手机号登录
                </div>
              </div>
            </div>
          </div>
          <!-- VIP信息 -->
          <div class="poppver-vip">
            <div class="vip-container ui-flex">
              <div class="vip-metas">
                <p class="vip-metas__meta ui-txt txt-caption txt-primary">
                  开通翼法学院VIP
                </p>
                <p class="vip-metas__meta ui-txt txt-caption">
                  为您的学习加速！
                </p>
              </div>
              <div class="vip-action">
                <el-button type="primary" size="small" @click="goToxufei"
                  >立即购买</el-button
                >
              </div>
            </div>
            <!--             
            <div class="user-is-vip" v-else>
              <div class="left_tips">
                <p>翼法学院VIP</p>
                <p>
                  {{
                    userInfo &&
                      userInfo.isVip &&
                      userInfo.isVip.deadline | date_format("YYYY-MM-DD")
                  }}到期
                </p>
              </div>
              <div class="right_button">
                <div class="buy-right-now" @click="goToxufei">立即续费</div>
              </div>
            </div> -->
          </div>
          <!-- 操作按钮 -->
          <div class="poppver-center-box">
            <ul class="box-container ui-cf">
              <li class="box-item ui-fl" @click="toProfile(1)">
                <img src="~static/images/header/user/kc.png" />我的课程
              </li>
              <li class="box-item ui-fl" @click="toProfile(3)">
                <img src="~static/images/header/user/wd.png" />订单中心
              </li>
              <li class="box-item ui-fl" @click="toProfile(2)">
                <img src="~static/images/header/user/sc.png" />我的收藏
              </li>
              <li class="box-item ui-fl" @click="toUserSetting">
                <img src="~static/images/header/user/sz.png" />个人设置
              </li>
            </ul>
          </div>

          <!-- 学习记录 -->
          <div class="poppver-studyrecord">
            <div class="studyrecord-header devide-line">
              <span class="dot"></span>
              <span class="ui-txt">学习记录</span>
              <span class="line"></span>
            </div>
            <ul class="record-list">
              <li v-if="newStudyLesson == null">
                暂无学习记录，快去学习新课程吧！
              </li>
              <li v-else>
                <div>
                  <img
                    src="~static/images/header/user/time.png"
                    width="15"
                    height="15"
                  />
                  {{ newStudyLesson.lessonName }}
                </div>
                <div>
                  <span>[回放]课程介绍（必看）</span>
                  <span @click="toPlayer(newStudyLesson.lessonId)">继续</span>
                </div>
              </li>
            </ul>
          </div>
          <div class="ui-divier"></div>
          <!-- 安全退出 -->
          <div class="poppver-logout">
            <el-button type="text" @click="removerLogin">安全退出</el-button>
          </div>
        </div>
      </template>
    </el-popover>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "ucAutoComplete",
  props: {
    loginStatus: Number
  },
  data() {
    return {
      state: "",
      showMenu: false,
      userInfo: {
        avatar: ""
      }
    };
  },
  computed: {
    ...mapState("user", {
      isVip: "isVip",
      nickName: "nickName",
      avatar: "avatar"
    }),
    // VIP 图标地址
    vipIconUrl() {
      return this.isVip
        ? require("static/images/header/user/icon-vip-light.png")
        : require("static/images/header/user/icon-vip-shade.png");
    },
    diamondIconUrl() {
      return this.isVip
        ? require("static/images/header/user/icon-diamond-light.png")
        : require("static/images/header/user/icon-diamond-shade.png");
    }
  },
  mounted() {},
  methods: {
    toLogin() {},
    toRegister() {},
    toProfile() {}
  }
};
</script>

<style scoped lang="scss" src="./user.scss"></style>

<style lang="scss">
.header-user-poppver {
  padding: 23px !important;
  box-sizing: border-box;
}
</style>
